package week14;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

public class OnlineNumber implements HttpSessionListener {
    private int onlineNum = 0;
    @Override
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
        System.out.println("有一个用户登录了。。。。。。。");
        onlineNum++;
        httpSessionEvent.getSession().getServletContext().setAttribute("onlineNum",onlineNum);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
        System.out.println("有一个用户离开了。。。。。。。");
        onlineNum--;
        httpSessionEvent.getSession().getServletContext().setAttribute("onlineNum",onlineNum);
    }
}
